package org.ceteca.explica.core.partners;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.common.BaseVO;
import org.ceteca.explica.core.warehouse.ProductGroupOT;



/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class DiscountOT extends BaseVO implements Serializable{


	private static final long serialVersionUID = 1L;
	private long idDisccount=0;
	private String description="";
	private double lowerLimit=0.0;
	private double upperLimit=0.0;
	private double percentage=0.0;
	
	private PartnerGroupOT partnerGroup;
	private ProductGroupOT productGroup;
	
	private Integer version=new Integer(0);
	
	
	


	public long getIdDiscount() {
		return idDisccount;
	}

	public void setIdDiscount(long idDisccount) {
		this.idDisccount = idDisccount;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public double getLowerLimit() {
		return lowerLimit;
	}

	public void setLowerLimit(double lowerLimit) {
		this.lowerLimit = lowerLimit;
	}

	public double getUpperLimit() {
		return upperLimit;
	}

	public void setUpperLimit(double upperLimit) {
		this.upperLimit = upperLimit;
	}

	public double getPercentage() {
		return percentage;
	}

	public void setPercentage(double percentage) {
		this.percentage = percentage;
	}

	public PartnerGroupOT getPartnerGroup() {
		return partnerGroup;
	}

	public void setPartnerGroup(PartnerGroupOT partnerGroup) {
		this.partnerGroup = partnerGroup;
	}

	public ProductGroupOT getProductGroup() {
		return productGroup;
	}

	public void setProductGroup(ProductGroupOT productGroup) {
		this.productGroup = productGroup;
	}

	public DiscountOT() {
		
	}

	@Override
	public boolean equals(Long id) {
		return id.longValue()==this.idDisccount;
	}

	@Override
	public String getEntityId() {
		return InterfacePartners.EXPLICA_ENTITY_DISCOUNT_ID;
	}

	@Override
	public long getInternalId() {
		return getIdDiscount();
	}

	@Override
	public String getInternalValue() {
		return getDescription();
	}

    @Override
    public int hashCode() {
        final HashCodeBuilder hcb = new HashCodeBuilder();
        hcb.append(getLowerLimit());
        hcb.append(getPartnerGroup());
        hcb.append(getProductGroup());
        return hcb.toHashCode();
    }

    
    
    @Override
    public boolean equals(Object obj) {
        boolean isEquals = false;
        try {
            final DiscountOT other = (DiscountOT)obj;
            final EqualsBuilder eqb = new EqualsBuilder();
            eqb.append(getLowerLimit(), other.getLowerLimit());
            eqb.append(getPartnerGroup(), other.getPartnerGroup());
            eqb.append(getProductGroup(), other.getProductGroup());
            isEquals = eqb.isEquals();

        } catch (Exception e) {
            isEquals = false;
        }

        return isEquals;
    }

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
	
    
	@Override
	public String toString() {
		
		
		StringBuffer result = new StringBuffer();
		
		
		
		try {
			result.append("\n%%%%%%%%%%%% DISCCOUNT %%%%%%%%%%%%%%%%%%%%");
			result.append("\nLower Limit: ");
			result.append(this.lowerLimit);
			result.append("\nUpper Limit: ");
			result.append(this.upperLimit);
			result.append("\nDisccoun Rate: ");
			result.append(this.percentage);
			
		}
		catch (Exception ex) {
			System.out.println("Error formatting DiscountOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
			
	
	}
	
	public String getProductGroupName(){
		if (getProductGroup()!=null)
			return getProductGroup().getDescription();
		else 
			return "";
	}
	
	public String getPartnerGroupName(){
		if (getPartnerGroup()!=null)
			return getPartnerGroup().getDescription();
		else 
			return "";
	}
    
}
